using Microsoft.VisualStudio.TestTools.UnitTesting;
using E = com.bodurov.SilverlightControls.XmlCodeEditor.Enums.XmlElement;
using A = com.bodurov.SilverlightControls.XmlCodeEditor.Enums.XmlArea;

namespace com.bodurov.SilverlightControls.XmlCodeEditor.Tests
{
    [TestClass]//[Ignore]
    public class IterativeTokenizerCanParseEntity : BaseTokenFixture
    {
        [TestMethod]//[Ignore]
        public void CanTokenizeEntity_IfItAppearsOnce()
        {
            const string str = "ABCD, EFGH&nbsp; XYZ";

            var tokenizer = new IterativeTokenizer();
            var tokens = tokenizer.ParseTokens(str);

            //TraceTokens(tokens);

            AssertTokens(tokens,
                Within(A.OutsideTag,
                    Expect("ABCD, EFGH", E.OutsideTagContent),
                    Expect("&nbsp;", E.Entity),
                    Expect(" XYZ", E.OutsideTagContent)));
        }

        [TestMethod]//[Ignore]
        public void CanTokenizeEntity_IfItAppearsTwice()
        {
            const string str = "ABCD, EFGH&nbsp; IN BTWN&#169; XYZ";

            var tokenizer = new IterativeTokenizer();
            var tokens = tokenizer.ParseTokens(str);

            //TraceTokens(tokens);

            AssertTokens(tokens,
                Within(A.OutsideTag,
                    Expect("ABCD, EFGH", E.OutsideTagContent),
                    Expect("&nbsp;", E.Entity),
                    Expect(" IN BTWN", E.OutsideTagContent),
                    Expect("&#169;", E.Entity),
                    Expect(" XYZ", E.OutsideTagContent)));
            }


        [TestMethod]//[Ignore]
        public void CanTokenizeEntity_IfAppearsConsequentiality()
        {
            const string str = "ABCD, EFGH&nbsp; IN BTWN&#169;&copy;&amp; XYZ";

            var tokenizer = new IterativeTokenizer();
            var tokens = tokenizer.ParseTokens(str);

            //TraceTokens(tokens);

            AssertTokens(tokens,
                Within(A.OutsideTag,
                    Expect("ABCD, EFGH", E.OutsideTagContent),
                    Expect("&nbsp;", E.Entity),
                    Expect(" IN BTWN", E.OutsideTagContent),
                    Expect("&#169;", E.Entity),
                    Expect("&copy;", E.Entity),
                    Expect("&amp;", E.Entity),
                    Expect(" XYZ", E.OutsideTagContent)));
        }


        [TestMethod]//[Ignore]
        public void CanTokenizeEntity_IfAppearsAtEnds()
        {
            const string str = "&copy;ABC\n\tEFG&nbsp;XYZ&spades;&#9830;";

            var tokenizer = new IterativeTokenizer();
            var tokens = tokenizer.ParseTokens(str);

            //TraceTokens(tokens);

            AssertTokens(tokens,
                Within(A.OutsideTag,
                    Expect("&copy;", E.Entity),
                    Expect("ABC", E.OutsideTagContent),
                    Expect_NewLine,
                    Expect("\tEFG", E.OutsideTagContent),
                    Expect("&nbsp;", E.Entity),
                    Expect("XYZ", E.OutsideTagContent),
                    Expect("&spades;", E.Entity),
                    Expect("&#9830;", E.Entity)));

        }

        [TestMethod]//[Ignore]
        public void CanTokenizeEntity_IfHasOneCharAtEnds()
        {
            const string str = "A&copy;B";

            var tokenizer = new IterativeTokenizer();
            var tokens = tokenizer.ParseTokens(str);

            //TraceTokens(tokens);

            AssertTokens(tokens,
                Within(A.OutsideTag,
                    Expect("A", E.OutsideTagContent),
                    Expect("&copy;", E.Entity),
                    Expect("B", E.OutsideTagContent)));

        }
    }
}